package edu.xust.service;

import edu.xust.mapper.RoleMapper;
import edu.xust.pojo.EquipBean;
import edu.xust.pojo.RoleBean;
import edu.xust.pojo.Story;
import edu.xust.utils.RoleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleService {
    @Autowired
    RoleMapper roleMapper;

    public void addRole(RoleBean role) {
        roleMapper.insertRole(role);
    }

    public RoleBean SelectRole(String username, String sex, String occupation) {
        //获取属性
        int[] property = RoleUtil.getProperty(occupation);
        int[] attack = RoleUtil.getAttach(property[1], property[2], property[1]);
        RoleBean role = new RoleBean();
        role.setUsername(username);//名字
        role.setSex(sex);//性别
        role.setOccupation(occupation);//职业
        role.setStrength(property[0]);//力量
        role.setPhysicial(property[1]);//体力
        role.setIntellige(property[2]);//智力

        role.setLife(attack[0]);//生命
        role.setMagic(attack[1]);//魔法
        role.setPattack(attack[2]);//物攻
        role.setMattack(attack[3]);//魔攻
        return role;
    }

    public void update(Integer id, Story story, Integer cap) {
        if (cap == 1)
            roleMapper.updateRoleStoryOf1(id);//章节1id
        if (cap == 2)
            roleMapper.updateRoleStoryOf2(id);//章节2id
        if (cap == 3)
            roleMapper.updateRoleStoryOf2(id);//章节3id
        if (story != null) {
            if (story.getEquip() != null)
                roleMapper.insertRoleEquip(story.getEquip());//装备
            roleMapper.updaateRoleExper(story.getExper());//经验
            roleMapper.updateMattack();//物攻
            roleMapper.updatePattack();//法攻
        }
    }

    public RoleBean findRole() {//查询角色信息
        return roleMapper.findRole();
    }

    public List<EquipBean> findEqu() {
        return roleMapper.selEqu();
    }
}
